 /********************************************************************************************\
 * libeds - extensible data structures library                                                *
 * Copyright (C) 2006, Dan Kruchinin, <just.asgard@gmail.com>                                 *
 *                                                                                            *
 * -> test/test_base.c                                                                        *
 *                                                                                            *
 * This library is free software; you can redistribute it and/or modify it under the terms of *
 * the GNU Lesser General Public License as published by the Free Software Foundation;        *
 * either version 2.1 of the License, or (at your option) any later version.                  *
 *                                                                                            *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;  *
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  *
 * See the GNU Lesser General Public License for more details.                                *
 *                                                                                            *
 * You should have received a copy of the GNU Lesser General Public License along with this   *
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,  *
 * Boston, MA 02111-1307 USA                                                                  *
 \********************************************************************************************/

#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "test/test_base.h"

void init_test_enviroment(void)
{
  initscr();
}

void end_test_enviroment(void)
{
  endwin();
}

void test_printf(const char* fmt, ...)
{
  va_list ap;
  char msg[TEST_LEN_MAX];

  va_start(ap, fmt);
  vsprintf(msg, fmt, ap);
  printw("%s", msg);
  refresh();
  va_end(ap);
}

void test_display_header(const char* msg)
{
  int x, y;

  getmaxyx(stdscr, y, x);
  move(0, x / 2);
  printw("%s", msg);
  refresh();
}

void test_next(void)
{
  int x, y;

  getmaxyx(stdscr, y, x);
  move(y - 1, x / 2);
  test_printf(":: TO NEXT TEST PRESS _ANY_ KEY ::");
  getch();
  clear();
}

void test_start_mark_output(void)
{
  attron(A_UNDERLINE);
}

void test_stop_mark_output(void)
{
  attroff(A_UNDERLINE);
}

void test_error(const char* fmt, ...)
{
  va_list ap;

  if(!isendwin())
	endwin();
  
  va_start(ap, fmt);
  fprintf(stderr, "\n--> ERROR:\n");
  vfprintf(stderr, fmt, ap);
  fputc('\n', stderr);
  va_end(ap);

  exit(EXIT_FAILURE);
}

void test_warning(const char* fmt, ...)
{
  va_list ap;

  if(!isendwin())
	endwin();

  va_start(ap, fmt);
  fprintf(stderr, "\n--> WARNING:\n");
  vfprintf(stderr, fmt, ap);
  fputc('\n', stderr);
  va_end(ap);
}

